home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1997 September
/
Macworld (1997-09).dmg
/
Serious Software
/
Cherwell Scientific Demos
/
pro Fit
/
pro Fit 5.0 demo (fpu).sea
/
pro Fit 5.0 demo (fpu)
/
Examples
/
Programming - intro
/
Test equality
< prev
next >
Wrap
Text File
|
1996-04-15
|
1KB
|
36 lines
{
This is a simple example that shows how to access the data window
from a program. To run the program, click the button "Add", then choose
the program "DataTest" from the menu "Misc".
This program compares the numbers in the first two columns of the
frontmost data window and writes '1' in the third column if they are
equal. Otherwise it writes a zero. If the cells of the first two columns
are empty, it erases the corresponding cell in the third column. When
it has finished, it writes the string 'done' into the results window.
}
program DataTest;
var i: integer;
function TestEquality(x,y:real):Boolean;
{ returns true if x and y are equal or nearly equal }
const epsilon =1e-7;
begin
if (x=0) and (y=0) then TestEquality := true
else TestEquality := abs(abs(x)-abs(y))/(abs(x)+abs(y)) < epsilon;
end;
begin
for i := 1 to nrRows do {loop through all rows}
if DataOK(i,1) and DataOK(i,2) then {if there is data in both columns}
begin
if TestEquality(data[i,1],data[i,2]) then {if the two columns are substantially equal}
data[i,3] := 1
else data[i,3] := 0; {if not equal}
end
else ClearData(i,3); {erase cell in column 3}
Writeln('done');
end;